import {observable, action} from "mobx";
import request from "../utils/request";
import * as api from "../api/api";
import {LoadHoc, loading} from '../hoc/loadHoc';

// 人才中心
export default class TalentStore extends LoadHoc {
  /**
   * 人才库
   */
  @observable allResumeInfo: api.YNJWTTalentCenterVOInformationsVO = {};

  @loading @action
  async getAllResumeInfo(params: {
    formProvinceId?: number, formMajorCategoryId?: number, formTechnicalTitleId?: number, formTypeOfJob?: number,
    pageIndex,
    pageSize
    callback?: (allResumeInfo: api.YNJWTTalentCenterVOInformationsVO) => void;
  }) {
    const {formProvinceId, formMajorCategoryId, formTechnicalTitleId, formTypeOfJob, pageIndex, pageSize,callback} = params;
    const allResumeInfo = await request(api.ApptalentCenterApiFetchParamCreactor.apptalentCenterGetAllResumeInfoAsync({
      formProvinceId,
      formMajorCategoryId,
      formTechnicalTitleId,
      formTypeOfJob,
      formSkipCount: (pageIndex-1)*pageSize,
      formMaxResultCount: pageSize
    }));
    this.allResumeInfo = allResumeInfo;
    callback && callback(allResumeInfo);
  }

  /**
   * 人才库-详情
   */
  @observable resumeInfo: api.YNJWTTalentCenterVOInformationsVO = {};

  @loading @action
  async getResumeInfo(params: {
    formId:number,
    callback?: (res: api.YNJWTTalentCenterVOInformationsVO) => void;
  }) {
    const {formId,callback} = params;
    const resumeInfo = await request(api.ApptalentCenterApiFetchParamCreactor.apptalentCenterGetResumeInfoAsync({
      formId
    }));
    this.resumeInfo = resumeInfo;
    callback && callback(resumeInfo);
  }

  /**
   *招聘信息
   */
  @observable allRecruitInfo: api.YNJWTTalentCenterVOInformationsVO = {};

  @loading @action
  async getAllRecruitInfo(params: {
    formProvinceId?: number, formCityId?: number, formStreetId?: number, formTypeOfJob?: number,
    pageIndex,
    pageSize
    callback?: (allRecruitInfo: api.YNJWTTalentCenterVOInformationsVO) => void;
  }) {
    const {formProvinceId, formCityId, formStreetId, formTypeOfJob, pageIndex, pageSize,callback} = params;
    const allRecruitInfo = await request(api.ApptalentCenterApiFetchParamCreactor.apptalentCenterGetAllRecruitInfoAsync({
      formProvinceId, formCityId, formStreetId, formTypeOfJob, formSkipCount: (pageIndex-1)*pageSize,
      formMaxResultCount: pageSize
    }));
    this.allRecruitInfo = allRecruitInfo;
    callback && callback(allRecruitInfo);
  }

  /**
   * 招聘信息-详情
   */
  @observable recruitInfo: api.YNJWTTalentCenterVOInformationsVO = {};

  @loading @action
  async getRecruitInfo(params: {
    formId:number,
    callback?: (res: api.YNJWTTalentCenterVOInformationsVO) => void;
  }) {
    const {formId,callback} = params;
    const recruitInfo = await request(api.ApptalentCenterApiFetchParamCreactor.apptalentCenterGetRecruitInfoAsync({
      formId
    }));
    this.recruitInfo = recruitInfo;
    callback && callback(recruitInfo);
  }

  /**
   * 获取专业类别 数据
   */
  @observable allMajorCategory: api.YNJWTTalentCenterVOMajorCategoryVO = {};

  @loading @action
  async getAllMajorCategory(params: {
    callback?: (res: api.YNJWTTalentCenterVOMajorCategoryVO) => void;
  }) {
    const {callback} = params;
    const allMajorCategory = await request(api.ApptalentCenterApiFetchParamCreactor.apptalentCenterGetAllMajorCategoryAsync({}));
    this.allMajorCategory = allMajorCategory;
    callback && callback(allMajorCategory);
  }

  /**
   * 获取职称 数据
   */
  @observable allTechnicalTitle: api.YNJWTTalentCenterVOTechnicalTitleVO = {};

  @loading @action
  async getAllTechnicalTitle(params: {
    callback?: (res: api.YNJWTTalentCenterVOTechnicalTitleVO) => void;
  }) {
    const {callback} = params;
    const allTechnicalTitle = await request(api.ApptalentCenterApiFetchParamCreactor.apptalentCenterGetAllTechnicalTitleAsync({}));
    this.allTechnicalTitle = allTechnicalTitle;
    callback && callback(allTechnicalTitle);
  }
}
